<?php
namespace app\home\controller;
use app\home\controller;
use app\home\model\DevicePartM;
use myResponse\Res;
use think\Db;
use think\Request;

class DevicePart extends Base{

// 批量修改备件
    function editMore(){
        $parts = input('')[0];
        $d = input('')[1];
        $m= new DevicePartM;
        foreach($parts as $v){
            $name=trim($v['pjmc']);
            if($name){  //名称不能空
                $v['pjmc']=$name;
                $v['sbid']=$d['sbid'];
                $v['sbmc']=$d['sbmc'];
                if($v['sbbjid']){   //修改
                    $m->editOne($v);
                }else{  //添加
                    $m->addOne($v);
                }
            }
        }
        Res::suc('ok');
    }

    //删除
    function delOne(){
        $m= new DevicePartM;
        $this->ret($m->delOne(),2);
    }

    function ret($z,$tp){
        $ret=['添加','修改','删除'];
        if($z)
            Res::suc($ret[$tp].'成功！');
        else
            Res::errs($ret[$tp].'失败！');
    }
}
